<?php

// @formatter:off
/**
 * @file comic.php
 * @author Alejandro Dario Simi
 * @date $Date: 2014-06-03 03:40:32 +0000 (Tue, 03 Jun 2014) $
 *
 * $Id: comic.php 112 2014-06-03 03:40:32Z daemonraco@gmail.com $
 * $URL: http://wcomix.googlecode.com/svn/trunk/services/tags/list/comic.php $
 */
// @formatter:on

require_once __DIR__."/../tools.php";

class WCServiceTagsListComic extends WCService {
	//
	// Class methods.
	public function __construct() {
		parent::__construct();

		$this->_requiredParams["url"][] = "group";
		$this->_requiredParams["url"][] = "comic";

		$this->_requiredPermissions["to"][] = WC_PERM_COMIC_VIEW;
		$this->_requiredPermissions["to"][] = WC_PERM_TAG_LIST;

		$this->_useCache = true;
	}
	//
	// Public methods.
	public function check() {
		if(parent::check()) {
			global $wcGroup;
			global $wcComic;

			if(!$wcGroup || !$wcGroup->ok()) {
				$this->setError(WC_HTTPERROR_INTERNAL_SERVER_ERROR, "There's something wrong with the specified group id");
			}
			if(!$wcComic || !$wcComic->ok()) {
				$this->setError(WC_HTTPERROR_INTERNAL_SERVER_ERROR, "There's something wrong with the specified comic id");
			}
			if($this->ok() && $wcGroup->id != $wcComic->group) {
				$this->setError(WC_HTTPERROR_INTERNAL_SERVER_ERROR, "Unmatching groups");
			}
		}

		return $this->ok();
	}
	//
	// Protected methods.
	protected function runGET() {
		global $wcComic;
		global $wcActiveTagsHolder;
		//
		// Comic tags list requested.
		foreach(WCTagsHolder::I()->tagsOfComic($wcComic) as $tag) {
			$this->_results[] = array(
				"id" => $tag->id,
				"name" => $tag->name,
				"special" => $wcActiveTagsHolder->isActive($tag->name)
			);
			$this->_count++;
		}
	}
}
